<?php
/**
 * @link https://ym2.cleverstone.top
 * @copyright Copyright (c) 2020 Yii Manager Software LLC
 */

namespace builder\widget;

use yii\base\Widget as BaseWidget;

/**
 * 解决部分小组件只能输出无法返回HTML内容
 * ```php
 * WidgetFacade::echo2Return(function () {
 *          \yii\bootstrap4\Modal::$autoIdPrefix = 'ModalB4';
 *          \yii\bootstrap4\Modal::begin([
 *                  'title' => 'ModalB4 title',
 *                  'bodyOptions' => [
 *                      'class' => 'text-center',
 *                  ],
 *                  'toggleButton' => [
 *                      'label' => 'ModalB4 btn',
 *                      'class' => 'layui-btn layui-btn-sm layui-btn-primary',
 *                  ],
 *          ]);
 *          echo implode("\n", array_fill(0, 100, 'ModalB4 content'));
 *          \yii\bootstrap4\Modal::end();
 * }),
 * ```
 * @author cleverstone
 * @since ym2.0
 */
class Echo2Return extends BaseWidget
{
    /**
     * @var \Closure 闭包中的组件
     */
    public $widget;

    /**
     * {@inheritdoc}
     */
    public function run()
    {
        if ($this->widget instanceof \Closure) {
            call_user_func($this->widget);
        }

        return '';
    }
}